<?

class Service extends Base_flexmodel {
	function __construct()
	{
		parent::__construct();
		$this->init('ics_services' , 'pro_id' , 'pro_name');
		//column : type_id, name, is_zone
	}
	
	function getAll ()
	{
		return parent::get( 'name' );
	}

	function getServiceList_byTypeId( $values=null, $fields=null, $offset=NULL, $limit=NULL )
	{
		return parent::_get_where_in ( 'type_id' , $values, $fields, $offset, $limit );
	}


	
//	function get($type = '') {
//		$sql = "select * from ics_services ";
//		if (strpos($type, ",")) 
//		{
//			$arr_id = explode(",",$type);
//			$long_id = null;
//			foreach($arr_id as $part_id)
//			{
//				$long_id .= $this->db->escape($part_id).",";
//			}
//			$long_id = substr($long_id, 0, (strlen($long_id)-1) );
//			
//			$sql .= " where type_id IN ($long_id) ";
//		} 
//		else if (trim($type) != '') 
//		{
//			$sql .= " where type_id = ".$this->db->escape($type)." ";			
//		}
//		if (!($type > 0)) $sql .= " order by name";
//
//		$q = $this->db->query($sql);
//		
//		if ($q->num_rows() > 0) {
//			return $q->result();
//		}
//		return false;		
//	}	



	
}



// <editor-fold defaultstate="collapsed" desc="PREVIOUS_CODE">
	
//	function getZoneState($type, $proId, $x, $y) {
//		if ($type == "" || $proId == "") return false;
//		$resultType = $this->isHaveZone($type, $proId);
//		$this->writeLog("\nhave zone : ".$resultType);
//		if ($resultType) {
//			$resultWhichHaveZone = $this->isInZone($type, $proId, $x, $y);
//			if ($resultWhichHaveZone) {
//				$state = "Y";
//			} else {
//				$state = "N";
//			}
//		} else {
//			//dont have zone
//			$state = "NA";
//		}
//		return $state;
//	}
//	
//	function isHaveZone($type, $pro_id='') {
//		$roid = ($pro_id != '')?" and pro_id='".$pro_id."'":"";
//		$ypeid = ($type != '')?" and type_id='".$type."'":"";
//		$sql = "select * from ics_zone where 1 ".$ypeid.$roid;
//		$this->writeLog("\nsql : ".$sql);
//		
//		// bind sql query
//		if($pro_id != '' || $type != '') $q = $this->db->query($sql,array($pro_id,$type));
//		else if($pro_id != '') $q = $this->db->query($sql,array($pro_id));
//		else if($type != '') $q = $this->db->query($sql,array($type));
//		else $q = $this->db->query($sql);
//		
//		if ($q->num_rows() > 0) {
//			return true;
//		}
//		return false;
//	}
//	
//	function getZoneStateforReport($type, $proId, $x, $y) {
//		if ($type == "" || $proId == "") return false;
//		echo "<font color=red>1. checking zone from ics_zone</font><br />";
//		$resultType = $this->isHaveZoneforReaport($type, $proId);
//		$this->writeLog("\nhave zone : ".$resultType);
//		if ($resultType) {
//			echo "<font color=red>2.Jika memiliki zone lalu cek XY dari input apa di dalam zone itu</font><br />";
//			$resultWhichHaveZone = $this->isInZoneforReport($type, $proId, $x, $y);
//			if ($resultWhichHaveZone) {
//				echo "<font color=red>3.Jika XY ($x,$y) terletak pada zone lalu assign sebagai Y</font><br />";
//				$state = "Y";
//			} else {
//				echo "<font color=red>3.Jika XY ($x,$y) tidak terletak pada zone lalu assign sebagai N</font><br />";
//				$state = "N";
//			}
//		} else {
//			echo "<font color=red>2.Jika tidak memiliki zone lalu assign sebagai NA</font><br />";
//			//dont have zone
//			$state = "NA";
//		}
//		return $state;
//	}
//	
//	function isHaveZoneforReaport($type, $pro_id='') {
//		$roid = ($pro_id != '')?" and pro_id='".$pro_id."'":"";
//		$ypeid = ($type != '')?" and type_id='".$type."'":"";
//		$sql = "select * from ics_zone where 1 ".$ypeid.$roid;
//		$this->writeLog("\nsql : ".$sql);
//		echo "<font color=red>query :</font><br />";
//		$sql_query = str_replace("from","<br />from",$sql);
//		$sql_query = str_replace("where","<br />where",$sql_query);
//		echo "<font color=red>".$sql_query."</font><br />";
//		$q = $this->db->query($sql);
//		if ($q->num_rows() > 0) {
//			return true;
//		}
//		return false;
//	}
//	
//	function isInZoneforReport($type, $pro_id, $x, $y) {
//		if ($type == "" || $pro_id == "" || !($x > 0 && $y > 0)) return false;
//		$data = $this->getZone($type, $pro_id);
//		//echo $type . "- ".$pro_id . "count > " .count($data)."\n";
//		if ($data) {
//			foreach ($data as $row) {
//				echo "<font color=red>query :</font><br />";
//				$report_query = str_replace("from","<br />from",$this->db->last_query());
//				$report_query = str_replace("where","<br />where",$report_query);
//				echo "<font color=red>".$report_query."</font><br />";
//				echo "<font color=red>has zone :</font><br />";
//				echo "<font color=red>".nl2br($row->zone)."</font><br />";
//				$zoneClient = $this->parseXy($row->zone);
//				$inZone = $this->ptInZone($zoneClient, $x, $y);
//				if ($inZone != 1) {
//					return true;
//				}
//			}			
//		}
//		return false;
//	}	
//	
//	function isInZone($type, $pro_id, $x, $y) {
//		if ($type == "" || $pro_id == "" || !($x > 0 && $y > 0)) return false;
//		$data = $this->getZone($type, $pro_id);
//		//echo $type . "- ".$pro_id . "count > " .count($data)."\n";
//		if ($data) {
//			foreach ($data as $row) {
//				$zoneClient = $this->parseXy($row->zone);
//				$inZone = $this->ptInZone($zoneClient, $x, $y);
//				if ($inZone != 1) {
//					return true;
//				}
//			}			
//		}
//		return false;
//	}	
//	
//	function inZone($pointer, $x, $y) {
//		$out =1;
//		$sumz = count($pointer);
//		$j = $sumz - 2;
//	
//		for ($i=0; $i<$sumz-1; $i+=2) {
//			if ( (($pointer[$i+1]<=$y) && ($y<$pointer[$j+1])) 
//				|| (($pointer[$j+1]<=$y) && ($y<$pointer[$i+1]))) {
//				if ($x < 
//					($pointer[$j]-$pointer[$i])*($y-$pointer[$i+1])/
//						($pointer[$j+1]-$pointer[$i+1])+$pointer[$i])  {
//					$out = 1 - $out;
//				}
//			}
//			$j = $i;
//		}
//		return $out;
//	}
//
//    function parseCXy($data) {
//            $data = explode(",", $data);
//			$return = array(); $idx = 1;
//            for ($i=0, $c=count($data); $i<$c; $i+=2) {
//                    if (isset($data[$i]) && isset($data[$i+1])) {
//			$return[$idx]['x'] = $data[$i];
//			$return[$idx]['y'] = $data[$i+1];
//			$idx++;
//                    }
//            }
//	return $return;
//    }
//	
//	
//	function parseXy($data) {
//			//update by akhyar
//			//last array is empty so must be erased
//			$dataSource0 = explode("\r\n", $data);
//			unset($dataSource);
//			foreach($dataSource0 as $value)
//			{
//				if($value!="" && $value !="\r" && $value !="\r\n")
//				$dataSource[] = $value;
//			}                
//			//end
//			if (count($dataSource) < 5) {
//					return $this->parseCXy($data);
//			}
//			$c = 0;
//			$datas = array();
//			for ($i=0, $c=count($dataSource); $i<$c; $i++) {
//					$xy = explode(",", $dataSource[$i]);
//					$datas[$i+1]['x'] = $xy[0];
//					$datas[$i+1]['y'] = $xy[1];
//			}
//			return $datas;
//	}
//	
//	function ptInZone($polyzoneXY,$x,$y) // 0 for inzone and 1 for not inzone
//	{
//		$count = count($polyzoneXY);
//		$inzone = FALSE;
//		$notInZone = 1;
//		$j = $count-1;
//		for($i=1;$i<$count;$i++)
//		{
//			if(($polyzoneXY[$i]['y'] < $y && $polyzoneXY[$j]['y'] >= $y) || ($polyzoneXY[$j]['y']<$y && $polyzoneXY[$i]['y'] >= $y))
//			{
//				$x0 = $polyzoneXY[$i]['x']+($y-$polyzoneXY[$i]['y'])/($polyzoneXY[$j]['y']-$polyzoneXY[$i]['y'])*($polyzoneXY[$j]['x']-$polyzoneXY[$i]['x']);
//				if($x0<$x) 
//				{
//					if($inzone === TRUE) {$inzone = FALSE;$notInZone=1;}
//					elseif($inzone === FALSE) {$inzone = TRUE;$notInZone=0;}
//				}
//			}
//			$j = $i;
//		}
//		//return $inzone;
//		return $notInZone ;
//	}
//
//
//	
//    function getRandomColor() {
//    	$d = array(0, 3, 6, 9, 12, 15);
//        $p0 = $d[mt_rand(0,5)];
//        $p1 = $d[mt_rand(0,5)];
//        $p2 = $d[mt_rand(0,5)];
//        $data = dechex($p0).dechex($p1).dechex($p2);
//        return $data;
//    }	
//    
//    function getColor($arrColor=array()) {
//    	/*
//    	$color = array("IndianRed","LightCoral","DarkSalmon","Crimson","Red","FireBrick","DarkRed",
//			"HotPink","DeepPink","MediumVioletRed","PaleVioletRed",
//			"Coral","Tomato","OrangeRed","DarkOrange","Orange",
//			"Gold","Yellow","DarkKhaki",
//			"Plum","Violet","Orchid","Fuchsia","Magenta","MediumOrchid",
//			"MediumPurple","BlueViolet","DarkViolet","DarkOrchid","DarkMagenta","Purple","Indigo","SlateBlue","DarkSlateBlue",
//			"GreenYellow","Chartreuse","LawnGreen","Lime","LimeGreen","SeaGreen","ForestGreen","Green","DarkGreen","YellowGreen","OliveDrab","Olive","DarkOliveGreen",
//			"MediumAquamarine","DarkSeaGreen","DarkCyan","Teal",
//			"CadetBlue","SteelBlue","Blue","MediumBlue","DarkBlue","Navy","MidnightBlue",
//			"BurlyWood","Tan","RosyBrown","Goldenrod","DarkGoldenrod","Peru","Chocolate","SaddleBrown","Sienna","Brown","Maroon",
//			"DarkGray","Gray", "DimGray","LightSlateGray","SlateGray","DarkSlateGray","Black");
//		$color = array("000", "300", "600", "900", "C00", "F00", "006",
//			"306", "606", "906", "C06", "F06", "00C", "30C", "60C", "90C", 
//			"C0C", "F0C");
//		*/
//		$color = array("000","300","600","900","C00","F00","003","303","603","903","C03","F03",
//			"006","306","606","906","C06","F06","009","309","609","909","C09","F09",
//			"00C","30C","60C","90C","C0C","F0C","00F","30F","60F","90F","C0F","F0F",
//			"030","330","630","930","C30","F30","033","333","633","933","C33","F33",
//			"036","336","636","936","C36","F36","039","339","639","939","C39","F39",
//			"03C","33C","63C","93C","C3C","F3C","03F","33F","63F","93F","C3F","F3F",
//			"060","360","660","960","C60","F60","063","363","663","963","C63","F63",
//			"066","366","666","966","C66","F66","069","369","669","969","C69","F69",
//			"06C","36C","66C","96C","C6C","F6C","06F","36F","66F","96F","C6F","F6F",
//			"090","390","690","990","C90","F90","093","393","693","993","C93","F93",
//			"096","396","696","996","C96","F96","099","399","699","999","C99","F99",
//			"09C","39C","69C","99C","C9C","F9C","09F","39F","69F","99F","C9F","F9F",
//			"0C0","3C0","6C0","9C0","CC0","FC0","0C3","3C3","6C3","9C3","CC3","FC3");
//		if (is_array($arrColor) && count($arrColor) > 0) {
//			$result = array_diff($color, $arrColor);
//			$c = $result[mt_rand(0,count($result)-1)];
//		} else {
//			$c = $color[mt_rand(0,count($color)-1)];
//		}
//		return $c;		
//    }
//
//	function errMessage($str) {
//		$d = "<?xml version=\"1.0\" encoding=\"UTF-8\"? >";
//		$d .= "<ics>\n<error>".$str."</error>\n</ics>";
//		$this->output->set_header("Content-type: text/xml");
//		$this->output->set_output($d);		
//	}
//	
//	function xmlHeader($type, $range, $block, $building, $street, $postal) {
//		$content = "<?xml version=\"1.0\" encoding=\"UTF-8\"? >";
//		$service = $type != '' ? $this->get($type) : false;
//		$name = $service != false ? $service[0]->name : '';
//		$content .= "<ics>\n"
//			. "<servicetype>".$type."</servicetype>\n"
//			. "<servicename>".htmlentities($name, ENT_QUOTES)."</servicename>\n"
//			. "<userlocation>\n";
//		if ($postal != '') { 
//			$content .= "<postal>".$postal."</postal>"; 
//		} else if ($building != '') { 
//			$content .= "<building>".$building."</building>"; 
//		} else {
//			if ($block != '') $content .= "<block>".$block."</block>";
//			if ($street != '') $content .= "<street>".$street."</street>";
//		} 
//		$content .= "</userlocation>\n";
//		if ($range > 0) { 
//			$content .= "<range>".$range."</range>\n";
//		}
//		//$this->output->set_header("Content-type: text/xml");
//		//$this->output->append_output($content);		
//		header("Content-type: text/xml");
//		echo $content;
//	}
//	
//	function formatFullAddress($result) {
//		$tmpAddr = $result->block != "" ? "Blk ".$result->block." " : "";
//		$tmpAddr .= $result->street." ".($result->unit != "" ? trim($result->unit) : ""). " ";
//		$tmpAddr .= $result->building != "" ? trim($result->building) ." " : "";
//		$tmpAddr .= "Singapore ".trim($result->postal) . ($result->telp != "" || $result->fax != "" ? "<br>" : "");
//		$tmpAddr .= $result->telp != "" ? "Tel: ".trim($result->telp)." " : "";
//		$tmpAddr .= $result->fax != "" ? "Fax: ".trim($result->fax) : "";	
//		return $tmpAddr;
//	}
//
//	function formatBubbleAddress($result) {
//		$tmpAddr = $result->block != "" ? "Blk ".trim($result->block)." " : "";
//		$tmpAddr .= $result->street." ".($result->unit != "" ? "<br>".trim($result->unit) : ""). " ";
//		$tmpAddr .= $result->building != "" ? trim($result->building) ." " : "";
//		$tmpAddr .= "<br>Singapore ".trim($result->postal) . ($result->telp != "" || $result->fax != "" ? "<br>" : "");
//		$tmpAddr .= $result->telp != "" ? "Tel: ".trim($result->telp)." " : "";
//		$tmpAddr .= $result->fax != "" ? "Fax: ".trim($result->fax) : "";	
//		return $tmpAddr;
//	}
//	
//	function xmlFooter() {
//		//$this->output->append_output("</ics>");
//		echo "</ics>";
//		die();
//	}
//	
//	
//	function xmlTag($pro_id, $pro_name, $distance, $state, $postal, $allserv=false, $servid='', $servname='') {
//		$name = htmlentities($pro_name, ENT_QUOTES);
//		$sname = htmlentities($servname, ENT_QUOTES);
//		$content = "\n";
//		$content .= "<provider><id>".$pro_id."</id><name>".$name."</name>";
//		if ($allserv && $servid != '' && $servname != '') { 
//			$content .= "<servicetype>".$servid."</servicetype>";
//			$content .= "<servicename>".$sname."</servicename>";
//		} 
//		$content .= sprintf("<distance>%01.2f</distance>", $distance);
//		$content .= "<state>".$state."</state>";
//		$content .= "<postalcode>".$postal."</postalcode></provider>";
//		//$this->output->append_output(str_replace('><',">\n<",$content));
//		echo str_replace('><',">\n<",$content);
//	}	
//	
//
//	/////////////////////////////////////////////////
//	function getZoneState($type, $proId, $x, $y) {
//		if ($type == "" || $proId == "") return false;
//		$resultType = $this->isHaveZone($type, $proId);
//		$this->writeLog("\nhave zone : ".$resultType);
//		if ($resultType) {
//			$resultWhichHaveZone = $this->isInZone($type, $proId, $x, $y);
//			if ($resultWhichHaveZone) {
//				$state = "Y";
//			} else {
//				$state = "N";
//			}
//		} else {
//			//dont have zone
//			$state = "NA";
//		}
//		return $state;
//	}
//	
//	function isHaveZone($type, $pro_id='') {
//		$roid = ($pro_id != '')?" and pro_id='".$pro_id."'":"";
//		$ypeid = ($type != '')?" and type_id='".$type."'":"";
//		$sql = "select * from ics_zone where 1 ".$ypeid.$roid;
//		$this->writeLog("\nsql : ".$sql);
//		
//		// bind sql query
//		if($pro_id != '' || $type != '') $q = $this->db->query($sql,array($pro_id,$type));
//		else if($pro_id != '') $q = $this->db->query($sql,array($pro_id));
//		else if($type != '') $q = $this->db->query($sql,array($type));
//		else $q = $this->db->query($sql);
//		
//		if ($q->num_rows() > 0) {
//			return true;
//		}
//		return false;
//	}
//	
//	function getZoneStateforReport($type, $proId, $x, $y) {
//		if ($type == "" || $proId == "") return false;
//		echo "<font color=red>1. checking zone from ics_zone</font><br />";
//		$resultType = $this->isHaveZoneforReaport($type, $proId);
//		$this->writeLog("\nhave zone : ".$resultType);
//		if ($resultType) {
//			echo "<font color=red>2.Jika memiliki zone lalu cek XY dari input apa di dalam zone itu</font><br />";
//			$resultWhichHaveZone = $this->isInZoneforReport($type, $proId, $x, $y);
//			if ($resultWhichHaveZone) {
//				echo "<font color=red>3.Jika XY ($x,$y) terletak pada zone lalu assign sebagai Y</font><br />";
//				$state = "Y";
//			} else {
//				echo "<font color=red>3.Jika XY ($x,$y) tidak terletak pada zone lalu assign sebagai N</font><br />";
//				$state = "N";
//			}
//		} else {
//			echo "<font color=red>2.Jika tidak memiliki zone lalu assign sebagai NA</font><br />";
//			//dont have zone
//			$state = "NA";
//		}
//		return $state;
//	}
//	
//	function isHaveZoneforReaport($type, $pro_id='') {
//		$roid = ($pro_id != '')?" and pro_id='".$pro_id."'":"";
//		$ypeid = ($type != '')?" and type_id='".$type."'":"";
//		$sql = "select * from ics_zone where 1 ".$ypeid.$roid;
//		$this->writeLog("\nsql : ".$sql);
//		echo "<font color=red>query :</font><br />";
//		$sql_query = str_replace("from","<br />from",$sql);
//		$sql_query = str_replace("where","<br />where",$sql_query);
//		echo "<font color=red>".$sql_query."</font><br />";
//		$q = $this->db->query($sql);
//		if ($q->num_rows() > 0) {
//			return true;
//		}
//		return false;
//	}
//	
//	function isInZoneforReport($type, $pro_id, $x, $y) {
//		if ($type == "" || $pro_id == "" || !($x > 0 && $y > 0)) return false;
//		$data = $this->getZone($type, $pro_id);
//		//echo $type . "- ".$pro_id . "count > " .count($data)."\n";
//		if ($data) {
//			foreach ($data as $row) {
//				echo "<font color=red>query :</font><br />";
//				$report_query = str_replace("from","<br />from",$this->db->last_query());
//				$report_query = str_replace("where","<br />where",$report_query);
//				echo "<font color=red>".$report_query."</font><br />";
//				echo "<font color=red>has zone :</font><br />";
//				echo "<font color=red>".nl2br($row->zone)."</font><br />";
//				$zoneClient = $this->parseXy($row->zone);
//				$inZone = $this->ptInZone($zoneClient, $x, $y);
//				if ($inZone != 1) {
//					return true;
//				}
//			}			
//		}
//		return false;
//	}	
//	
//	function isInZone($type, $pro_id, $x, $y) {
//		if ($type == "" || $pro_id == "" || !($x > 0 && $y > 0)) return false;
//		$data = $this->getZone($type, $pro_id);
//		//echo $type . "- ".$pro_id . "count > " .count($data)."\n";
//		if ($data) {
//			foreach ($data as $row) {
//				$zoneClient = $this->parseXy($row->zone);
//				$inZone = $this->ptInZone($zoneClient, $x, $y);
//				if ($inZone != 1) {
//					return true;
//				}
//			}			
//		}
//		return false;
//	}	
//	
//	function inZone($pointer, $x, $y) {
//		$out =1;
//		$sumz = count($pointer);
//		$j = $sumz - 2;
//	
//		for ($i=0; $i<$sumz-1; $i+=2) {
//			if ( (($pointer[$i+1]<=$y) && ($y<$pointer[$j+1])) 
//				|| (($pointer[$j+1]<=$y) && ($y<$pointer[$i+1]))) {
//				if ($x < 
//					($pointer[$j]-$pointer[$i])*($y-$pointer[$i+1])/
//						($pointer[$j+1]-$pointer[$i+1])+$pointer[$i])  {
//					$out = 1 - $out;
//				}
//			}
//			$j = $i;
//		}
//		return $out;
//	}
//
//    function parseCXy($data) {
//            $data = explode(",", $data);
//			$return = array(); $idx = 1;
//            for ($i=0, $c=count($data); $i<$c; $i+=2) {
//                    if (isset($data[$i]) && isset($data[$i+1])) {
//			$return[$idx]['x'] = $data[$i];
//			$return[$idx]['y'] = $data[$i+1];
//			$idx++;
//                    }
//            }
//	return $return;
//    }
//	
//	
//	function parseXy($data) {
//			//update by akhyar
//			//last array is empty so must be erased
//			$dataSource0 = explode("\r\n", $data);
//			unset($dataSource);
//			foreach($dataSource0 as $value)
//			{
//				if($value!="" && $value !="\r" && $value !="\r\n")
//				$dataSource[] = $value;
//			}                
//			//end
//			if (count($dataSource) < 5) {
//					return $this->parseCXy($data);
//			}
//			$c = 0;
//			$datas = array();
//			for ($i=0, $c=count($dataSource); $i<$c; $i++) {
//					$xy = explode(",", $dataSource[$i]);
//					$datas[$i+1]['x'] = $xy[0];
//					$datas[$i+1]['y'] = $xy[1];
//			}
//			return $datas;
//	}
//	
//	function ptInZone($polyzoneXY,$x,$y) // 0 for inzone and 1 for not inzone
//	{
//		$count = count($polyzoneXY);
//		$inzone = FALSE;
//		$notInZone = 1;
//		$j = $count-1;
//		for($i=1;$i<$count;$i++)
//		{
//			if(($polyzoneXY[$i]['y'] < $y && $polyzoneXY[$j]['y'] >= $y) || ($polyzoneXY[$j]['y']<$y && $polyzoneXY[$i]['y'] >= $y))
//			{
//				$x0 = $polyzoneXY[$i]['x']+($y-$polyzoneXY[$i]['y'])/($polyzoneXY[$j]['y']-$polyzoneXY[$i]['y'])*($polyzoneXY[$j]['x']-$polyzoneXY[$i]['x']);
//				if($x0<$x) 
//				{
//					if($inzone === TRUE) {$inzone = FALSE;$notInZone=1;}
//					elseif($inzone === FALSE) {$inzone = TRUE;$notInZone=0;}
//				}
//			}
//			$j = $i;
//		}
//		//return $inzone;
//		return $notInZone ;
//	}
//
//
//	
//    function getRandomColor() {
//    	$d = array(0, 3, 6, 9, 12, 15);
//        $p0 = $d[mt_rand(0,5)];
//        $p1 = $d[mt_rand(0,5)];
//        $p2 = $d[mt_rand(0,5)];
//        $data = dechex($p0).dechex($p1).dechex($p2);
//        return $data;
//    }	
//    
//    function getColor($arrColor=array()) {
//    	/*
//    	$color = array("IndianRed","LightCoral","DarkSalmon","Crimson","Red","FireBrick","DarkRed",
//			"HotPink","DeepPink","MediumVioletRed","PaleVioletRed",
//			"Coral","Tomato","OrangeRed","DarkOrange","Orange",
//			"Gold","Yellow","DarkKhaki",
//			"Plum","Violet","Orchid","Fuchsia","Magenta","MediumOrchid",
//			"MediumPurple","BlueViolet","DarkViolet","DarkOrchid","DarkMagenta","Purple","Indigo","SlateBlue","DarkSlateBlue",
//			"GreenYellow","Chartreuse","LawnGreen","Lime","LimeGreen","SeaGreen","ForestGreen","Green","DarkGreen","YellowGreen","OliveDrab","Olive","DarkOliveGreen",
//			"MediumAquamarine","DarkSeaGreen","DarkCyan","Teal",
//			"CadetBlue","SteelBlue","Blue","MediumBlue","DarkBlue","Navy","MidnightBlue",
//			"BurlyWood","Tan","RosyBrown","Goldenrod","DarkGoldenrod","Peru","Chocolate","SaddleBrown","Sienna","Brown","Maroon",
//			"DarkGray","Gray", "DimGray","LightSlateGray","SlateGray","DarkSlateGray","Black");
//		$color = array("000", "300", "600", "900", "C00", "F00", "006",
//			"306", "606", "906", "C06", "F06", "00C", "30C", "60C", "90C", 
//			"C0C", "F0C");
//		*/
//		$color = array("000","300","600","900","C00","F00","003","303","603","903","C03","F03",
//			"006","306","606","906","C06","F06","009","309","609","909","C09","F09",
//			"00C","30C","60C","90C","C0C","F0C","00F","30F","60F","90F","C0F","F0F",
//			"030","330","630","930","C30","F30","033","333","633","933","C33","F33",
//			"036","336","636","936","C36","F36","039","339","639","939","C39","F39",
//			"03C","33C","63C","93C","C3C","F3C","03F","33F","63F","93F","C3F","F3F",
//			"060","360","660","960","C60","F60","063","363","663","963","C63","F63",
//			"066","366","666","966","C66","F66","069","369","669","969","C69","F69",
//			"06C","36C","66C","96C","C6C","F6C","06F","36F","66F","96F","C6F","F6F",
//			"090","390","690","990","C90","F90","093","393","693","993","C93","F93",
//			"096","396","696","996","C96","F96","099","399","699","999","C99","F99",
//			"09C","39C","69C","99C","C9C","F9C","09F","39F","69F","99F","C9F","F9F",
//			"0C0","3C0","6C0","9C0","CC0","FC0","0C3","3C3","6C3","9C3","CC3","FC3");
//		if (is_array($arrColor) && count($arrColor) > 0) {
//			$result = array_diff($color, $arrColor);
//			$c = $result[mt_rand(0,count($result)-1)];
//		} else {
//			$c = $color[mt_rand(0,count($color)-1)];
//		}
//		return $c;		
//    }
//
//	function errMessage($str) {
//		$d = "<?xml version=\"1.0\" encoding=\"UTF-8\"? >";
//		$d .= "<ics>\n<error>".$str."</error>\n</ics>";
//		$this->output->set_header("Content-type: text/xml");
//		$this->output->set_output($d);		
//	}
//	
//	function xmlHeader($type, $range, $block, $building, $street, $postal) {
//		$content = "<?xml version=\"1.0\" encoding=\"UTF-8\"? >";
//		$service = $type != '' ? $this->get($type) : false;
//		$name = $service != false ? $service[0]->name : '';
//		$content .= "<ics>\n"
//			. "<servicetype>".$type."</servicetype>\n"
//			. "<servicename>".htmlentities($name, ENT_QUOTES)."</servicename>\n"
//			. "<userlocation>\n";
//		if ($postal != '') { 
//			$content .= "<postal>".$postal."</postal>"; 
//		} else if ($building != '') { 
//			$content .= "<building>".$building."</building>"; 
//		} else {
//			if ($block != '') $content .= "<block>".$block."</block>";
//			if ($street != '') $content .= "<street>".$street."</street>";
//		} 
//		$content .= "</userlocation>\n";
//		if ($range > 0) { 
//			$content .= "<range>".$range."</range>\n";
//		}
//		//$this->output->set_header("Content-type: text/xml");
//		//$this->output->append_output($content);		
//		header("Content-type: text/xml");
//		echo $content;
//	}
//	
//	function formatFullAddress($result) {
//		$tmpAddr = $result->block != "" ? "Blk ".$result->block." " : "";
//		$tmpAddr .= $result->street." ".($result->unit != "" ? trim($result->unit) : ""). " ";
//		$tmpAddr .= $result->building != "" ? trim($result->building) ." " : "";
//		$tmpAddr .= "Singapore ".trim($result->postal) . ($result->telp != "" || $result->fax != "" ? "<br>" : "");
//		$tmpAddr .= $result->telp != "" ? "Tel: ".trim($result->telp)." " : "";
//		$tmpAddr .= $result->fax != "" ? "Fax: ".trim($result->fax) : "";	
//		return $tmpAddr;
//	}
//
//	function formatBubbleAddress($result) {
//		$tmpAddr = $result->block != "" ? "Blk ".trim($result->block)." " : "";
//		$tmpAddr .= $result->street." ".($result->unit != "" ? "<br>".trim($result->unit) : ""). " ";
//		$tmpAddr .= $result->building != "" ? trim($result->building) ." " : "";
//		$tmpAddr .= "<br>Singapore ".trim($result->postal) . ($result->telp != "" || $result->fax != "" ? "<br>" : "");
//		$tmpAddr .= $result->telp != "" ? "Tel: ".trim($result->telp)." " : "";
//		$tmpAddr .= $result->fax != "" ? "Fax: ".trim($result->fax) : "";	
//		return $tmpAddr;
//	}
//	
//	function xmlFooter() {
//		//$this->output->append_output("</ics>");
//		echo "</ics>";
//		die();
//	}
//	
//	
//	function xmlTag($pro_id, $pro_name, $distance, $state, $postal, $allserv=false, $servid='', $servname='') {
//		$name = htmlentities($pro_name, ENT_QUOTES);
//		$sname = htmlentities($servname, ENT_QUOTES);
//		$content = "\n";
//		$content .= "<provider><id>".$pro_id."</id><name>".$name."</name>";
//		if ($allserv && $servid != '' && $servname != '') { 
//			$content .= "<servicetype>".$servid."</servicetype>";
//			$content .= "<servicename>".$sname."</servicename>";
//		} 
//		$content .= sprintf("<distance>%01.2f</distance>", $distance);
//		$content .= "<state>".$state."</state>";
//		$content .= "<postalcode>".$postal."</postalcode></provider>";
//		//$this->output->append_output(str_replace('><',">\n<",$content));
//		echo str_replace('><',">\n<",$content);
//	}	
//	

// </editor-fold>


	
// <editor-fold defaultstate="collapsed" desc="UNUSED">

//	function writeLog($content) {
//		/*
//		$filename = "/var/www/html/aic/log/log.txt";
//		if (is_writable($filename)) {
//		    if (!$handle = fopen($filename, 'a')) {
//		         echo "Cannot open file ($filename)";
//		         exit;
//		    }		
//		    // Write $somecontent to our opened file.
//		    if (fwrite($handle, $content) === FALSE) {
//		        echo "Cannot write to file ($filename)";
//		        exit;
//		    }
//		} else {
//			echo "The file $filename is not writable";
//		}
//		*/
//	}

	
	/*
	function ptInZone($pointerXY, $x, $y) {
		$result = 1;
		$count = count($pointerXY);
		$j = $count-1;
		for ($i=1; $i<=$count; $i++) {
			if (!isset($pointerXY[$i]['y']) || !isset($pointerXY[$j]['y'])) continue;
			if (($pointerXY[$i]['y'] <= $y && $y < $pointerXY[$j]['y']) ||
			($pointerXY[$j]['y'] <= $y && $y < $pointerXY[$i]['y'])) {
				$x0 = ($pointerXY[$j]['x'] - $pointerXY[$i]['x']) * ($y - $pointerXY[$i]['y']) /
				($pointerXY[$j]['y'] - $pointerXY[$i]['y']) + $pointerXY[$i]['x'];
				if ($x < $x0) {
					$result = 1 - $result;
				}
			}
			$j = $i;
		}
		return $result;
	}
	*/
	
	 // </editor-fold>





	/////////LUM IMPLEMENT, tar DL SC nya dl
//	public function search($term) {
//		$term = $this->db->escape($term);
//
//		$sql = "SELECT posts.*,
//			CASE WHEN posts.title REGEXP $term THEN 1 ELSE 0 END AS keyword_in_title,
//			MATCH ( posts.title, posts.body ) AGAINST ($term) AS mysql_score
//			FROM posts
//			WHERE ( posts.title REGEXP $term OR posts.body REGEXP $term )
//			ORDER BY keyword_in_title DESC, mysql_score DESC, posts.date DESC LIMIT 0, 10";
//
//		$res = $this->db->query($sql);  
//		$items = array();
//		if ($res->num_rows() > 0) {
//			$count = 0;
//			foreach ($res->result() as $item) {
//				foreach ($item as $key => $value) {
//					$items[$count][$key] = $value;
//				}
//				$count++;
//			}
//		} 
//		return $items;
//	}



